package tools;

import java.awt.GridLayout;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;

class EditarConexoes extends JDialog {
	private static final long serialVersionUID = -4315020634571127596L;
	
	private boolean isOK;
	private JCheckBox[] conexoes;
	
	private static final String[] lbls = {"Conexão Cima:", "Conexão Direita:", "Conexão Baixo:", "Conexão Esquerda:"};

	public EditarConexoes (boolean[] conexoes) {
		super ((JDialog) null, "Editar Bloco Atual");
		this.setLayout (new GridLayout(5, 2));
		this.conexoes = new JCheckBox [4];
		for (int i = 0; i < conexoes.length; i++) {
			this.conexoes[i] = new JCheckBox ();
			this.conexoes[i].setSelected(conexoes[i]);
			this.add (new Label(lbls[i]));
			this.add (this.conexoes[i]);
		}
		
		isOK = false;		
		JButton btnOK = new JButton ("Ir");
		btnOK.addActionListener(new ActionListener () {
			@Override public void actionPerformed (ActionEvent e) {
				isOK = true;
				setVisible(false);
			}
		});
		JButton btnCancelar = new JButton ("Cancelar");
		btnCancelar.addActionListener(new ActionListener () {
			@Override public void actionPerformed (ActionEvent e) {
				setVisible(false);
			}
		});
		
		this.add (btnOK);
		this.add (btnCancelar);
		
        this.pack();
        this.setLocationRelativeTo(null);
        this.setResizable(false);
        this.setModal(true);
        this.setVisible(true);
	}
	
	public boolean isOK () {
		return this.isOK;
	}
	
	public boolean[] getConexoes () {
		boolean[] con = new boolean [conexoes.length];
		for (int i = 0; i < con.length; i++) {
			con[i] = conexoes[i].isSelected();
		}
		return con;
	}
}
